<?php

/**
 * 抽奖商品管理
 * ============================================================================
 * 版权所有 2005-2009 上海商派网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.ecshop.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: liubo $
 * $Id: wj_lottery.php 16881 2009-12-14 09:19:16Z liubo $
 */

define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
//require_once(ROOT_PATH . 'includes/lib_goods.php');
//require_once(ROOT_PATH . 'includes/lib_order.php');

/* 检查权限 */
//admin_priv('group_by');

/* act操作项的初始化 */
if (empty($_REQUEST['act']))
{
    $_REQUEST['act'] = 'list';
}
else
{
    $_REQUEST['act'] = trim($_REQUEST['act']);
}

/*------------------------------------------------------ */
//-- 抽奖商品列表
/*------------------------------------------------------ */

if ($_REQUEST['act'] == 'list')
{
    /* 模板赋值 */
    $smarty->assign('full_page',    1);
    $smarty->assign('ur_here',      "抽奖列表");
    $smarty->assign('action_link',  array('href' => 'wj_lottery.php?act=add', 'text' => "添加抽奖商品"));

    $sql="select * from ".$GLOBALS['ecs']->table('lottery');
    $list = $GLOBALS['db']->getAll($sql);


    $smarty->assign('wj_lottery_list',  $list['item']);
    $smarty->assign('filter',           $list['filter']);
    $smarty->assign('record_count',     $list['record_count']);
    $smarty->assign('page_count',       $list['page_count']);

    $sort_flag  = sort_flag($list['filter']);
    $smarty->assign($sort_flag['tag'], $sort_flag['img']);

    /* 显示商品列表页面 */
    assign_query_info();
    $smarty->display('wj_lottery_list.htm');
}
elseif ($_REQUEST['act'] == 'list_lg')
{
    /* 模板赋值 */
    $smarty->assign('full_page',    1);
    $smarty->assign('ur_here',      "抽奖商品列表");
    $smarty->assign('action_link',  array('href' => 'wj_lottery.php?act=add', 'text' => "添加抽奖商品"));

    $lg_id = intval($_REQUEST['id']);
	if ($lg_id <= 0)
    {
           die('invalid param');
    }
	$list = wj_lottery_lg_list($lg_id);

    $smarty->assign('wj_lottery_list',  $list['item']);
    $smarty->assign('filter',           $list['filter']);
    $smarty->assign('record_count',     $list['record_count']);
    $smarty->assign('page_count',       $list['page_count']);

    $sort_flag  = sort_flag($list['filter']);
    $smarty->assign($sort_flag['tag'], $sort_flag['img']);

    /* 显示商品列表页面 */
    assign_query_info();
    $smarty->display('wj_lottery_list.htm');
}
elseif ($_REQUEST['act'] == 'query')
{
    $list = wj_lottery_list();

    $smarty->assign('wj_lottery_list', $list['item']);
    $smarty->assign('filter',         $list['filter']);
    $smarty->assign('record_count',   $list['record_count']);
    $smarty->assign('page_count',     $list['page_count']);

    $sort_flag  = sort_flag($list['filter']);
    $smarty->assign($sort_flag['tag'], $sort_flag['img']);

    make_json_result($smarty->fetch('wj_lottery_list.htm'), '',
        array('filter' => $list['filter'], 'page_count' => $list['page_count']));
}

/*------------------------------------------------------ */
//-- 添加/编辑抽奖商品
/*------------------------------------------------------ */

elseif ($_REQUEST['act'] == 'add' || $_REQUEST['act'] == 'edit')
{
    /* 初始化/取得抽奖商品信息 */
    if ($_REQUEST['act'] == 'add')
    {
        $wj_lottery = array(
            'id'  => 0,
			'total' =>0
        );
    }
    else
    {
        $wj_lottery_id = intval($_REQUEST['id']);
        if ($wj_lottery_id <= 0)
        {
            die('invalid param');
        }
        $wj_lottery = wj_lottery_info($wj_lottery_id);
		$wj_lottery['proper'] = "(".(floatval(1.00/$wj_lottery['pro'])*100)."%)";
    }
    $smarty->assign('wj_lottery', $wj_lottery);
	

    /* 模板赋值 */
    $smarty->assign('ur_here', "抽奖商品");
    $smarty->assign('action_link', list_link($_REQUEST['act'] == 'add'));
    $smarty->assign('cat_list', cat_list());
    $smarty->assign('brand_list', get_brand_list());
//	$smarty->assign('lg_list', get_lottery_group_list());

    /* 显示模板 */
    assign_query_info();
    $smarty->display('wj_lottery_info.htm');
}


?>